package com.chen.project.white_jotter.service.admin;

import com.chen.project.white_jotter.mapper.AdminRoleMapper;
import com.chen.project.white_jotter.pojo.AdminRole;
import com.chen.project.white_jotter.utils.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class RoleService {

    @Resource
    private AdminRoleMapper adminRoleMapper;

    @Resource
    private RedisUtil redisUtil;

    public List<AdminRole> getRoleList(){

        List<AdminRole> adminRoles = null;
        if(redisUtil.get("role_list") != null){
            adminRoles = (List<AdminRole>) redisUtil.get("role_list");
        }
        else{
            adminRoles = adminRoleMapper.selectList(null);
            redisUtil.set("role_list", adminRoles);
            redisUtil.expire("role_list", 30L, TimeUnit.SECONDS);
        }
        return adminRoles;
    }
}
